//
//  PECumulativeGainCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/12.
//

#import "RHEnergyStatisticsCell.h"
#import "RHEnergyStatisticsChartView.h"

@interface RHEnergyStatisticsCell()
@property (nonatomic ,strong) RHEnergyStatisticsChartView *chartView;
@end
@implementation RHEnergyStatisticsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

-(void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    QMUILabel *leftLab = [self.contentView viewWithTag:100];
    leftLab.text = [NSString stringWithFormat:@"%ldt",[dic[@"accumulatedRevenue"] integerValue]];
    
    QMUILabel *rightLab = [self.contentView viewWithTag:101];
    rightLab.text = [NSString stringWithFormat:@"%ldt",[dic[@"yesterdayRevenue"] integerValue]];
}

- (void)setChartModel:(DevChartModel *)chartModel{
    _chartModel = chartModel;

    [_chartView setChartModel:_chartModel];
}

- (void)setupUI{
    self.backgroundColor = UIColor.clearColor;
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColor.whiteColor;
    [bgView.layer setCornerRadius:8];
    bgView.layer.masksToBounds = YES;
    bgView.layer.borderColor = kCOLOR_HEX(@"#E3E6ED").CGColor;
    bgView.layer.borderWidth = 1;
    [self.contentView addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    //------------------------
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = @"能量统计".rh_localized;
    titleLab.textColor = kCOLOR_HEX(@"#171A1D");
    titleLab.textAlignment = NSTextAlignmentRight;
    titleLab.font = kBOLDSYSTEMFONT(16);
    [bgView addSubview:titleLab];
 
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.left.mas_offset(15);
    }];
    
    
    NSInteger type = 0;
    if ([self.reuseIdentifier containsString:@"Month"]) {
        type = 1;
    }
    //功率统计(只有日曲线)
    if ([self.reuseIdentifier containsString:@"PEPowerStatisticsCell"]) {
        type = 2;
    }
    if ([self.reuseIdentifier containsString:@"Year"]) {
        type = 0;
    }
    _chartView = [[RHEnergyStatisticsChartView alloc] initWithFrame:CGRectMake(5, 5,SCREEN_WIDTH-40, 250+130) type:type isLandscape:NO];
    _chartView.layer.cornerRadius = 8;
    _chartView.layer.masksToBounds = YES;
    _chartView.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:_chartView];
    kWeakSelf;
    _chartView.fullChartBlock = ^{
        if (weakSelf.fullChartBlock) {
            weakSelf.fullChartBlock();
        }
    };
    _chartView.selectTopToolBlock = ^(NSInteger index) {
        if (weakSelf.selectTopToolBlock) {
            weakSelf.selectTopToolBlock(index);
        }
    };
    
    _chartView.subTimeBlock = ^{//日期往前
        if (weakSelf.subTimeBlock) {
            weakSelf.subTimeBlock();
        }
    };
    
    _chartView.addTimeBlock = ^{//日期往后
        if (weakSelf.addTimeBlock) {
            weakSelf.addTimeBlock();
        }
    };
    
    _chartView.changeTimeBlock = ^{
        if (weakSelf.changeTimeBlock) {
            weakSelf.changeTimeBlock();
        }
    };
    
    
    [_chartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(5);
        make.right.mas_offset(-5);
        make.top.equalTo(titleLab.mas_bottom).offset(0);
        make.bottom.mas_offset(0);
    
    }];
}


@end
